package com.jdrx.sw.sewage.api.web;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.jdrx.platform.commons.rest.beans.vo.ResponseVO;
import com.jdrx.platform.commons.rest.beans.vo.ResposeVO;
import com.jdrx.platform.commons.rest.factory.ResponseFactory;
import com.jdrx.platform.commons.rest.factory.ResponseFactory2;
import com.jdrx.sw.sewage.beans.dto.log.AddLogDTO;
import com.jdrx.sw.sewage.beans.dto.log.QueryLogDTO;
import com.jdrx.sw.sewage.beans.vo.OptionVO;
import com.jdrx.sw.sewage.common.constant.Constant;
import com.jdrx.sw.sewage.service.LogService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api("行为分析")
@RestController
@RequestMapping(value = "api/log", method = RequestMethod.POST)
public class LogApi {
	@Autowired
	private LogService logService;
	
	@ApiOperation(value = "新增日志")
	@RequestMapping(value = "add")
	public ResposeVO add(@RequestBody @Validated AddLogDTO dto) throws Exception {
		logService.add(dto);
		return ResponseFactory.ok("操作成功");
	}
	
	@ApiOperation(value = "分页查询行为分析")
	@RequestMapping(value = "pageList")
	public ResposeVO pageList(@RequestBody @Validated QueryLogDTO dto,
							  @RequestHeader(value = Constant.TENANT_ID, required = false) String tenantId) {
		if(StringUtils.isNotBlank(tenantId) && !StringUtils.equals(tenantId, "null")) {
			dto.setTenantId(Long.valueOf(tenantId));
		}
		return ResponseFactory.ok(logService.pageList(dto));
	}
	
	@ApiOperation(value = "租户选项")
	@RequestMapping(value = "tenantOptions")
	public ResponseVO<List<OptionVO>> tenantOptions() {
		return ResponseFactory2.ok(logService.tenantOptions());
	}
	
	@ApiOperation(value = "站点选项")
	@RequestMapping(value = "stationOptions")
	public ResponseVO<List<OptionVO>> stationOptions() {
		return ResponseFactory2.ok(logService.stationOptions());
	}
	
	@ApiOperation(value = "用户选项")
	@RequestMapping(value = "userOptions")
	public ResponseVO<List<OptionVO>> userOptions() {
		return ResponseFactory2.ok(logService.userOptions());
	}
	
	@ApiOperation(value = "事件选项")
	@RequestMapping(value = "eventOptions")
	public ResponseVO<List<OptionVO>> eventOptions() {
		return ResponseFactory2.ok(logService.eventOptions());
	}
}